import * as types from '../types';

const state ={
	dashboard:{
		name:'',
		time:'',
		addr:'',
		role:'',
		pv:0,
		amount:0,
		news:0
	}
};

const actions = {
	init({commit}){
		commit(types.INIT_DATA);
	}
};

const getters = {
	dashboard:state=>state.dashboard,
	role:state=>{
		state.dashboard.role = state.dashboard.name == 'admin' ? '超级管理员' : '普通员工';

		console.log(state.dashboard.role);
	}
};

const mutations = {
	[types.INIT_DATA](state){
		console.log(state);
		const time = `${new Date().getYear()+1900}/${new Date().getMonth()+1}/${new Date().getDate()}`;
		const name = localStorage.getItem('ms_username');
		const news = 1000;
		const amount = 10000;
		state.dashboard = {
			name,
			time,
			news,
			amount
		}
	}
};

export default {
	state,
	actions,
	getters,
	mutations
}